import Vue from 'vue'
import iView from 'iview'
import VueRouter from 'vue-router'
import Routers from './router'
import Util from './libs/util'
import App from './app.vue'
import 'iview/dist/styles/iview.css'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {get, post, fetchGrid } from './libs/header.js'
import { uploadFile } from './libs/uploadFile'
import 'es6-promise/auto'
import axios from 'axios'
window.Vue = Vue
Vue.use(ElementUI);
Vue.use(VueRouter)

Vue.use(iView)
    //moment
import moment from 'moment' //导入文件
Vue.prototype.$moment = moment; //赋值使用
Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$fetchGrid = fetchGrid;
Vue.prototype.$uploadFile = uploadFile
    // 步骤条
import StepBar from './components/StepBar'
Vue.component('StepBar', StepBar)

// 我的审核 table 栏
import MyTrialTab from './components/MyTrialTab'
Vue.component('MyTrialTab', MyTrialTab)

// 上传
import UploadFile from './components/UploadFile'
Vue.component('UploadFile', UploadFile)

import fileUpload from './components/fileUpload'
Vue.component('fileUpload', fileUpload)

// 下载
import DownloadButton from './components/DownloadButton'
Vue.component('DownloadButton', DownloadButton)

//旧的名字
import Oldname from './components/Oldname'
Vue.component('Oldname', Oldname)

// 建设单位
import BuildName from './components/BuildName'
Vue.component('BuildName', BuildName)
    //打印
import PrintButton from './components/Print'
Vue.component('PrintButton', PrintButton)

//查看按钮
import ButtonShow from './components/ButtonShow'
Vue.component('ButtonShow', ButtonShow)

// 谷歌地图
// import * as VueGoogleMaps from 'vue2-google-maps'
// Vue.use(VueGoogleMaps, {
//     load: {
//         // key: 'AIzaSyCDoZwHDtJ0GKx-U9Y-SZwgL_5vNDeDBKs'
//         key: 'AIzaSyBMax06DjAJoHnTK1HBZNLh3GBxBETJ7Vw',
//         libraries: 'places',
//     },
//     loadCn: true
// })
import BaiduMap from 'vue-baidu-map'
// 百度地图
Vue.use(BaiduMap, {
        // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
        ak: 'LVf1osslOvyXyglNCsg2ULK9otcY6P2o'
    })
    // import { BmlMarkerClusterer } from 'vue-baidu-map'
    // Vue.component('bml-marker-clusterer', BmlMarkerClusterer)
import { request, social } from './libs/axios'
window.axios = request
window.social = social

// 数组扩展
import './libs/array'

// 路由配置
const RouterConfig = {
    mode: 'history',
    routes: Routers
}
const router = new VueRouter(RouterConfig)

router.beforeEach((to, from, next) => {
    iView.LoadingBar.start()
    Util.title(to.meta.title)
    next()
    post('member.islogin',{}).then(res => {
        if (res._STATUS == 0 && to.path != '/loagin') {
            next({ path: '/login' })
        } else {
            next()
        }
    })
})

router.afterEach(() => {
    iView.LoadingBar.finish()
    window.scrollTo(0, 0)
})

// vuex
import store from './store'

new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})